package  com.macllvm.whale.protocol;

import java.util.concurrent.atomic.AtomicInteger;
import android.util.Log;
import com.macllvm.whale.settings.SystemSettings;

public class  PacketPackager {
    private static final String TAG = "PacketPackager";
    static  AtomicInteger  packetCount = new  AtomicInteger(1);

    private static SystemSettings systemSettings;

    public static void setSystemSettings(SystemSettings settings) {
        systemSettings = settings;
    }

    public static String packagePacket(int command, String attachedData){
        StringBuffer  buffer = new  StringBuffer(256);
        buffer.append(ProtocolBase.IPTUX_VERSION);
        buffer.append(":" );
        buffer.append(String.valueOf(packetCount.get()));
        buffer.append(":" );
        buffer.append(systemSettings.getSettingValue(SystemSettings.KEY_NAME[1]));
        buffer.append(":");
        buffer.append(systemSettings.getSettingValue(SystemSettings.KEY_NAME[0]));
        buffer.append(":" );
        buffer.append(String.valueOf(command));
        buffer.append(":" );

        if(null != attachedData)
            buffer.append(attachedData);
        int result = packetCount.addAndGet(1);
        return  buffer.toString();
    }
}